home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / mail / mailchec.lha / mailcheck.s < prev   
Text File  |  1995-04-15  |  10KB  |  555 lines

  1. ***************************************************
  2. * MAILCHECK - pop up a requester if a file is hit!
  3. *
  4. * (c) Apr 15 1995 By C.H.Skilbeck
  5. *
  6. * Usage:
  7. *
  8. * 'run <>nil: mailcheck uumail:username (..uumail:username..etc)' (1st time)
  9. * (can specify up to 16 filenames... any others ignored (silently...))
  10. * or 'mailcheck off' to suspend checking
  11. * or 'mailcheck on' to resume checking
  12. * or 'mailcheck quit' to kill the mailchecker
  13. *
  14. * bugs/limitations:
  15. *
  16. * slaps a requester on front screen - even if it isn't public - HAVETHAT!
  17. * doesn't stop notification requests when switched off, just doesn't requester
  18. * just looks at first 2 chrs of args when sending messages to the daemon
  19. * various memory leaks on some bombout conditions - fuck that!
  20. * file(s) must exist at startup time
  21. * error checking all a bit crap
  22. *
  23. *
  24. *
  25. *
  26. ***************************************************
  27.  
  28. ; do multi file thing
  29.  
  30.     opt    c-,o+,ow-
  31.  
  32.     incdir    include:
  33.  
  34.     include    exec/nodes.i
  35.     include    exec/ports.i
  36.     include    exec/io.i
  37.     include    dos/dos.i
  38.     include    dos/notify.i
  39.     include    req/reqbase.i
  40.  
  41.     include    hd:text/proto/lvo.offs
  42.  
  43. FrontScreen    =  60
  44. FirstWindow    =  4
  45.  
  46. NRS    = NotifyRequest_SIZEOF
  47.  
  48. ***************************************************
  49.  
  50. main    move.l    a7,stak
  51.  
  52.     clr.l    dosbase
  53.     clr.l    intbase
  54.     clr.l    reqbase    libs
  55.  
  56.     clr.l    gotport
  57.     clr.l    gotreplyport    ports
  58.  
  59.     clr    numbnuts
  60.  
  61.     move    d0,argc
  62.     move.l    a0,argv    args
  63.     bsr    grabargs
  64.  
  65.     lea    taskport,a4    Add the message port
  66.     lea    name,a5
  67.  
  68.     bsr    initport    port found/created...?
  69.  
  70.     tst.l    d0
  71.     beq.s    .firsttime
  72.  
  73.     move.l    d0,-(a7)
  74.  
  75.     ;reet - it's running already, check args for on,off,quit
  76.  
  77.     lea    replyname,a5
  78.     lea    replyport,a4
  79.     bsr    createport    ;snaff up a reply port
  80.     st    gotreplyport
  81.  
  82.     ;init a message,
  83.  
  84.     move.l    argptrs,a3
  85.  
  86.     tst    numargs
  87.     bne.s    .kewl
  88.  
  89.     lea    soddingabout,a3
  90.  
  91. .kewl    lea    message,a0
  92.     move    #MN_SIZE+2,MN_LENGTH(a0)
  93.     move.l    #replyport,MN_REPLYPORT(a0)
  94.     move.b    (a3)+,MN_SIZE(a0)
  95.     move.b    (a3)+,MN_SIZE+1(a0)
  96.  
  97.     ;send the message
  98.  
  99.     move.l    4.w,a6
  100.     move.l    (a7)+,a0
  101.     lea    message,a1
  102.     jsr    LVO_PutMsg(a6)
  103.  
  104.     ;get the reply,
  105.  
  106.     lea    replyport,a0
  107.     jsr    LVO_GetMsg(a6)
  108.  
  109.     ;knob off.
  110.  
  111.     bra    .bombout
  112.  
  113.     ;ELSE...
  114.  
  115. .firsttime    st    gotport
  116.     st    telling
  117.  
  118.     move.l    4.w,a6
  119.     lea    intname,a1
  120.     moveq    #0,d0
  121.     jsr    LVO_OldOpenLibrary(a6)
  122.     MOVE.L    D0,intbase
  123.     beq    .bombout
  124.  
  125.     MOVE.L    4.w,A6
  126.     LEA    reqname,A1
  127.     MOVEQ    #0,D0
  128.     jsr    LVO_OldOpenLibrary(a6)
  129.     MOVE.L    D0,reqbase
  130.     beq    .bombout
  131.  
  132.     move.l    4.w,a6
  133.     lea    dosname,a1
  134.     jsr    LVO_OldOpenLibrary(a6)    Open dos, ALLRIGHT??~!?~
  135.     move.l    d0,dosbase
  136.     beq    .bombout
  137.  
  138.     move.l    d0,a6
  139.     jsr    LVO_Output(a6)
  140.     move.l    d0,stdout
  141.  
  142.     tst    numargs
  143.     bne.s    .okmanf
  144.  
  145.     lea    usage,a4
  146.     bsr    treq
  147.     bra    .bombout
  148.  
  149. .okmanf    ;scan through args list of filenames...?
  150.  
  151.     move    numargs,d7
  152.     subq    #1,d7
  153.     lea    argptrs,a5
  154.     lea    notifyreq,a4
  155.     lea    namebuf,a3
  156.  
  157. .gogocheckfilenames    movem.l    d7/a3-a5,-(a7)
  158.  
  159.     move.l    dosbase,a6
  160.  
  161.     move.l    (a5),d1
  162.     move.l    #MODE_OLDFILE,d2    open file
  163.     jsr    LVO_Open(a6)
  164.     move.l    d0,handle
  165.     bne.s    .swff    no such file!?!?!
  166.  
  167.     lea    flerr,a4
  168.     bsr    treq
  169.     bra    .bombout
  170.  
  171. .swff    ;stash off full name in list of full names
  172.  
  173.     move.l    d0,d1
  174.     move.l    a3,d2
  175.     move.l    #256,d3
  176.     jsr    LVO_NameFromFH(a6)    get file's full name..
  177.  
  178.     move.l    handle,d1
  179.     jsr    LVO_Close(a6)    close it
  180.  
  181.     ;OK, bang up 1 notify per file name
  182.  
  183.     move.l    a4,a0
  184.     moveq    #NRS-1,d7    clear the shitty noti
  185. .clrn    clr.b    (a0)+
  186.     dbra    d7,.clrn
  187.  
  188.     move.l    a4,a0
  189.     move.l    a3,nr_Name(a0)    ;wot file
  190.     move.l    a3,nr_FullName(a0)
  191.     move.l    #taskport,nr_Port(a0)
  192.     move.l    #9,nr_Flags(a0)    ;msg, and wait for reply
  193.  
  194.     ; Start 1 for each file
  195.  
  196.     move.l    a0,d1
  197.     jsr    LVO_StartNotify(a6)    ;start notificationness....
  198.  
  199.     ;******** HMMMMMMMMMMM ? STRESS.........
  200.  
  201.     tst.l    d0
  202.     beq    .bombout    ;ok?
  203.  
  204.     movem.l    (a7)+,d7/a3-a5
  205.  
  206. .skippy    tst.b    (a3)+
  207.     bne.s    .skippy
  208.  
  209.     lea    NRS(a4),a4    next notify
  210.     addq.w    #4,a5
  211.     addq    #1,numbnuts
  212.  
  213.     dbra    d7,.gogocheckfilenames
  214.  
  215.     ;wait for it to get hit (or a BREAK signal...)
  216.  
  217.     lea    taskport,a0
  218.     moveq    #0,d0
  219.     move.b    MP_SIGBIT(a0),d0
  220.     moveq    #1,d1
  221.     lsl.l    d0,d1
  222.     bset    #12,d1    CTRL_C sigbit
  223.     move.l    d1,signalset
  224.  
  225. ;********************************************
  226. ;MAIN TASK PORT WAIT MESSAGE LOOP BIT THING
  227. ;********************************************
  228.  
  229. .wait    move.l    4.w,a6
  230.     move.l    signalset,d0
  231.     jsr    LVO_Wait(a6)
  232.  
  233.     ;got one! break or notify?
  234.  
  235.     btst    #12,d0
  236.     bne    .reetquit    ;ctrl - c quits it
  237.  
  238.     ;get message to ident file
  239.  
  240.     move.l    4.w,a6
  241.     lea    taskport,a0
  242.     jsr    LVO_GetMsg(a6)
  243.     tst.l    d0
  244.     beq.s    .wait
  245.  
  246.     move.l    d0,-(a7)
  247.  
  248.     move.l    d0,a0    ;OK, size check??
  249.     move    MN_LENGTH(a0),d0
  250.     cmp    #MN_SIZE+2,d0
  251.     bne.s    .notif
  252.  
  253.     move.b    MN_SIZE(a0),d0    ;snaff the message!
  254.     and.b    #223,d0
  255.     lsl    #8,d0
  256.     move.b    MN_SIZE+1(a0),d0
  257.     and.b    #223,d0
  258.  
  259.     cmp    #'OI',d0
  260.     beq.s    .sodding
  261.  
  262.     cmp    #'ON',d0
  263.     beq.s    .turnon
  264.  
  265.     cmp    #'OF',d0
  266.     beq.s    .turnoff
  267.  
  268.     cmp    #'QU',d0
  269.     beq.s    .quitter
  270.  
  271. .sodding    lea    soddingabout,a4
  272.     bsr    treq
  273.     bra    .waitloop
  274.  
  275. .turnon    st    telling
  276.     bra    .waitloop
  277.  
  278. .turnoff    sf    telling
  279.     bra    .waitloop
  280.  
  281. .quitter    addq.w    #4,a7
  282.  
  283. .reetquit    lea    tellquit,a4
  284.     bsr    treq
  285.  
  286.     bra    .mainexit0
  287.  
  288.     ;tell which file
  289.  
  290. .notif    tst.b    telling
  291.     beq.s    .waitloop    unless it's switched off
  292.  
  293.     lea    textbuffer,a2
  294.  
  295.     lea    tell,a1
  296.  
  297. .cpy0    move.b    (a1)+,d0
  298.     beq.s    .cc
  299.     move.b    d0,(a2)+
  300.     bra.s    .cpy0
  301.  
  302. .cc    move.l    nm_NReq(a0),a0
  303.     move.l    nr_FullName(a0),a0
  304. .cpy1    move.b    (a0)+,d0
  305.     beq.s    .cc1
  306.     move.b    d0,(a2)+
  307.     bra.s    .cpy1
  308.  
  309. .cc1    clr.b    (a2)+
  310.  
  311.     lea    textbuffer,a4
  312.     bsr    treq
  313.  
  314. .waitloop    move.l    4.w,a6
  315.     move.l    (a7)+,a1
  316.     jsr    LVO_ReplyMsg(a6)    cheers
  317.  
  318.     bra    .wait
  319.  
  320. ***************************************************
  321.  
  322. .mainexit0    move    numbnuts,d7
  323.     subq    #1,d7
  324.     lea    notifyreq,a5
  325. .killem    move.l    a5,d1
  326.     move.l    dosbase,a6
  327.     jsr    LVO_EndNotify(a6)    ditch ALL the notifies
  328.     lea    NRS(a5),a5
  329.     dbra    d7,.killem
  330.  
  331. .bombout    move.l    stak,a7
  332.  
  333.     move.l    4.w,a6
  334.  
  335.     tst.l    gotreplyport
  336.     beq.s    .no
  337.     lea    replyport,a1    ditch reply port
  338.     bsr    ditchport
  339.  
  340. .no    tst.l    gotport
  341.     beq.s    .no1
  342.     lea    taskport,a1
  343.     bsr    ditchport    ditch task port
  344.  
  345. .no1    move.l    4.w,a6
  346.     move.l    dosbase,d0
  347.     beq.s    .nod
  348.     move.l    d0,a1
  349.     jsr    LVO_CloseLibrary(a6)
  350. .nod    move.l    intbase,d0
  351.     beq.s    .nod1
  352.     move.l    d0,a1
  353.     jsr    LVO_CloseLibrary(a6)
  354. .nod1    move.l    reqbase,d0
  355.     beq.s    .nod2
  356.     move.l    d0,a1
  357.     jsr    LVO_CloseLibrary(a6)
  358. .nod2
  359.     moveq    #0,d0
  360.     rts
  361.  
  362. ***************************************
  363. * Find the message port or create it
  364.  
  365. initport    move.l    4.w,a6
  366.     jsr    LVO_Forbid(a6)    !
  367.     lea    name,a1
  368.     jsr    LVO_FindPort(a6)    ...
  369.     move.l    d0,-(a7)
  370.     jsr    LVO_Permit(a6)    ?
  371.     move.l    (a7)+,d0
  372.     beq.s    createport
  373.  
  374.     rts    ; if d0 != 0, then it's the port!
  375.  
  376. createport    bsr    getsignal    grab a signal bit
  377.     move.l    d0,-(a7)
  378.  
  379.     move.l    a4,a1
  380.     moveq    #7,d7
  381. .gg    clr.l    (a1)+
  382.     dbra    d7,.gg
  383.  
  384.     move.l    4.w,a6
  385.     sub.l    a1,a1
  386.     jsr    LVO_FindTask(a6)
  387.     move.l    d0,MP_SIGTASK(a4)
  388.     move.l    (a7)+,d0
  389.     move.b    d0,MP_SIGBIT(a4)
  390.     move.l    a5,LN_NAME(a4)
  391.     move.b    #5,LN_PRI(a4)
  392.     move.b    #NT_MSGPORT,LN_TYPE(a4)
  393.     move.l    a4,a1
  394.     jsr    LVO_AddPort(a6)    Add the Port
  395.  
  396.     moveq    #0,d0
  397.     rts
  398.  
  399. *** Grab a signal bit
  400.  
  401. getsignal    move.l    4.w,a6
  402.     moveq    #-1,d0
  403.     jsr    LVO_AllocSignal(a6)
  404.     rts
  405.  
  406. ditchport    moveq    #0,d0
  407.     move.b    MP_SIGBIT(a1),d0
  408.     move.l    d0,-(a7)
  409.     jsr    LVO_RemPort(a6)
  410.     move.l    (a7)+,d0
  411.     jsr    LVO_FreeSignal(a6)    Free the signal bit
  412.     rts
  413.  
  414. *** compare strings at a0,a1 (uppercase them)
  415.  
  416. strcmp    move.b    (a0)+,d0
  417.     move.b    (a1)+,d1
  418.     beq.s    .yes
  419.     and    #224,d0
  420.     cmp.b    d0,d1
  421.     beq.s    strcmp
  422.     moveq    #0,d0
  423.     rts
  424. .yes    moveq    #-1,d0
  425.     rts
  426.  
  427. ** DO a shitty text request!
  428.  
  429. treq    move.l    intbase,a6
  430.     lea    trq,a2
  431.     move.l    FrontScreen(a6),a3
  432.     move.l    FirstWindow(a3),d3    front screen, or 0
  433.     move.l    d3,TR_Window(a2)
  434.     clr.l    TR_MiddleText(a2)
  435.     clr.l    TR_PositiveText(a2)
  436.     clr.l    TR_NegativeText(a2)
  437.     move.l    #knobmsg,TR_NegativeText(a2)
  438.     move.l    #knobmsg1,TR_PositiveText(a2)
  439.     move    #1,TR_TextColor(a2)
  440.     move.l    a4,TR_Text(a2)
  441.     clr.l    TR_Controls(a2)
  442.     move    #AMIGAKEYS,TR_KeyMask(a2)
  443.     move.l    #title,TR_Title(a2)
  444.     move.l    reqbase,a6
  445.     move.l    a2,a0
  446.     jsr    LVO_TextRequest(a6)
  447.     rts
  448.  
  449. **************************************************
  450. *
  451. * GRABARGS :
  452. * numargs    : how many words...
  453. * argptrs    : numargs pointers into
  454. * args    : safely stashed bytes (null termed...)
  455.  
  456. grabargs    move.l    argv,a0
  457.     move    argc,d0
  458.     lea    args,a1
  459.     lea    argptrs,a2
  460.     clr.b    (a1)
  461.     clr.l    (a2)
  462.     move    #254,d6
  463.     moveq    #0,d7
  464.     subq    #2,d0
  465.     bmi.s    .exit
  466. .nxtarg    cmp    #16,d7
  467.     bge.s    .exit
  468.     addq    #1,d7
  469.     move.l    a1,(a2)+    got an arg ! stash ptr
  470.     move.b    #' ',d5
  471.     cmp.b    #'"',(a0)
  472.     bne.s    .grabarg
  473.     addq.l    #1,a0
  474.     dbra    d0,.go
  475.     clr.b    (a1)
  476.     bra.s    .exit
  477. .go    move.b    #'"',d5
  478. .grabarg    move.b    (a0)+,d1    getchr
  479.     cmp.b    d5,d1    =' '? (or '"')
  480.     beq.s    .gots
  481.     move.b    d1,(a1)+    no,stashit
  482.     subq    #1,d6
  483.     bmi.s    .fullup
  484.     dbra    d0,.grabarg    next
  485. .fullup    clr.b    (a1)
  486.     bra.s    .exit
  487. .gots    clr.b    (a1)+
  488. .tst    cmp.b    #' ',(a0)
  489.     beq.s    .skippy
  490.     cmp.b    #9,(a0)
  491.     beq.s    .skippy
  492.     dbra    d0,.nxtarg
  493.     bra.s    .exit
  494. .skippy    addq.w    #1,a0
  495.     dbra    d0,.tst
  496. .exit    move    d7,numargs
  497.     rts
  498.  
  499. ***************************************************
  500.  
  501.     section    blab,data
  502.  
  503. dosname    dc.b    "dos.library",0
  504. reqname    dc.b    "req.library",0
  505. intname    dc.b    "intuition.library",0
  506. name    dc.b    "MAILCHECK_PORT",0
  507. replyname    dc.b    "MAILCHECK_REPLY_PORT",0
  508. title    dc.b    "MailCheck v1.0 (c) 1995 CHS",0
  509. tell    dc.b    "File has been hit :",0
  510. tellquit    dc.b    "Mailcheck sodding off, allreeeet?",0
  511. soddingabout    dc.b    "OI! Stop sodding about, you fool!",0
  512. usage    dc.b    "Specify filename(s) and stop cunting about",0
  513. knobmsg    dc.b    "Have that!",0
  514. knobmsg1    dc.b    "Have this!",0
  515. flerr    dc.b    "One or more of those files are not there, dickcheese..",0
  516.  
  517. ***************************************************
  518.  
  519.     section    crap,bss
  520.  
  521. notifyreq    ds.b    NotifyRequest_SIZEOF*16    some notify requests
  522. signalset    ds.l    1    signals to watch
  523. gotport    ds.l    1    got a taskport?
  524. gotreplyport    ds.l    1    got a replyport?
  525. numbnuts    ds.w    1    how many requests requested
  526. namebuf    ds.b    1024    filenames
  527. handle    ds.l    1    filehandles
  528.  
  529. stdout    ds.l    1
  530.  
  531. stak    ds.l    1
  532.  
  533. dosbase    ds.l    1
  534. intbase    ds.l    1
  535. reqbase    ds.l    1
  536.  
  537. telling    ds.b    4    switched on or off?
  538.  
  539. numargs    ds.w    1
  540. args    ds.b    256
  541. argptrs    ds.l    16
  542. argc    ds.w    1
  543. argv    ds.l    1
  544.  
  545. textbuffer    ds.b    256    for messages
  546.  
  547. trq    ds.b    TR_SIZEOF*8
  548. message    ds.b    MN_SIZE+2    4 byte message
  549. taskport    ds.b    MP_SIZE    the main port
  550. replyport    ds.b    MP_SIZE    a little reply one
  551.  
  552. ***************************************************
  553.  
  554.     end
  555.